import { NestFactory } from '@nestjs/core'
import { INestApplication, INestExpressApplication } from '@nestjs/common'
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface'
import { from, Observable, OperatorFunction } from 'rxjs'
import { switchMap } from 'rxjs/operators'
export type MeepoApplication = INestApplication & INestExpressApplication
export function bootstrap(
  port: number,
  host: string,
  module: any,
  httpServer: any,
  options: NestApplicationOptions,
  ...pipes: OperatorFunction<MeepoApplication, MeepoApplication>[]
): Observable<any> {
  return from(NestFactory.create(module, httpServer, options)).pipe(
    ...pipes,
    switchMap((app: MeepoApplication) => {
      app.enableCors()
      return from(app.listen(port, host))
    })
  )
}
